package animationCollision;

import java.awt.Color;
import java.awt.Graphics;

public class Ball extends Shape {
	float x, y; // Ball's center x and y 
	float radius; // Ball's radius 
	private Color color; // Ball's color
	private static final Color DEFAULT_COLOR = Color.BLUE;
	private static final float DEFAULT_ANGLE_IN_DEGREES = 30;

	public Ball(float x, float y, float radius, float speed, float angleInDegree, Color color) {
		this.x = x;
		this.y = y;
		// Convert (speed, angle) to (x, y), with y-axis inverted
		this.speedX = (float) (speed * Math.cos(Math.toRadians(angleInDegree)));
		this.speedY = (float) (-speed * (float) Math.sin(Math.toRadians(angleInDegree)));
		this.radius = radius;
		this.color = color;
	}

	public Ball(float x, float y, float radius, float speed, float angleInDegree) {
		this(x, y, radius, speed, angleInDegree, DEFAULT_COLOR);
	}

	public Ball(float radius, float speed) {
		this(0, 0, radius, speed, DEFAULT_ANGLE_IN_DEGREES, DEFAULT_COLOR);
	}

	/** Draw itself using the given graphics context. */
	public void draw(Graphics g) {
		x = x < 0 ? 0 : x;
		y = y < 0 ? 0 : y;
		g.setColor(color);
		g.fillOval((int) (x - radius), (int) (y - radius), (int) (2 * radius), (int) (2 * radius));
	}

	/** Return mass - r^3 suppose */
	@Override
	public float getMass() {
		return radius * radius * radius / 1000f;
	}

}
